<?php

declare(strict_types=1);
/**
 * This file is part of MineAdmin.
 *
 * @link     https://www.mineadmin.com
 * @document https://doc.mineadmin.com
 * @contact  root@imoi.cn
 * @license  https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
 */

namespace App\Model;

use Hyperf\Database\Model\Relations\BelongsTo;
use Hyperf\Database\Model\Relations\HasMany;

/**
 * App\Distributor
 *
 * @property int $id
 * @property int $device_id 设备id
 * @property string $port_name 插孔名称
 * @property int $port_bin 插孔号
 * @property int $over_load 0=正常 1=过载
 * @property int $over_current 0=正常 1=过流
 * @property int $over_temp 0=正常 1=过温
 * @property int $no_load 0=正常 1=空载
 * @property int $charge_status 0=未充电 1=充电中 2=充满 3=时间到
 * @property int $is_fault 计量电路故障 0=正常 1=故障
 * @property int $inline 0=离线 1=在线
 * @property int $fault_message
    0-未发生，1-发生
    Bit0：过压告警 over_voltage
    Bit1：欠压告警 under_voltage
    Bit2：继电器粘连 relay stick
    Bit3：保险丝烧毁 fuse cut-out
    Bit4：计量异常  Metering error
    Bit5：过温告警   over_temp
    Bit6：漏电告警   leakage_alarm
    Bit7：充电器故障 charger_error
    Bit8：气溶胶触发 aerosol_trigger
    Bit9：接地故障
    Bit10:短路
    Bit11:CP故障
    Bit12：过流
 * @property int $times 每次打开，业务加+1；0x0000表示没有在充电
 * @property float $power 功率定点1位小数，0~10000表示0~1000.0W，如225表示22.5W
 * @property float $current 定点3位小数，0.000A~+10.000A，如5000表示5.000A
 * @property float $elec 定点3位小数0.000kWh~+65.000kWh，如4200表示4.200kWh
 * @property int $min 分钟 充电时间
 * @property float $volt 电压 2字节 单位 0.1V
 */
class DevicePort extends Model
{
    public bool $timestamps = true;

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'device_port';

    public array $faultMap = [
        0 => 'over_voltage',      // Bit0
        1 => 'under_voltage',     // Bit1
        2 => 'relay_stick',       // Bit2
        3 => 'fuse_cut_out',      // Bit3
        4 => 'metering_error',    // Bit4
        5 => 'over_temp',         // Bit5
        6 => 'leakage_alarm',     // Bit6
        7 => 'charger_error',     // Bit7
        8 => 'aerosol_trigger',   // Bit8
        9 => 'ground_fault',      // Bit9
        10 => 'short_circuit',    // Bit10
        11 => 'cp_fault',         // Bit11
        12 => 'over_current',     // Bit12
    ];


    protected array $fillable = [
        'device_id','port_name','port_bin','over_load','over_current',
        'over_temp','no_load','charge_status','is_fault','inline','fault_message',
        'times', 'power','current','elec','min','volt'
    ];

    protected array $casts = [
        'created_at'=>'datetime',
        'updated_at'=>'datetime'
    ];

    /**所属设备
     * @return BelongsTo
     */
    public function device():BelongsTo{
        return $this->belongsTo(Device::class,'device_id','id');
    }


}
